﻿
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
#include "ace.VertexBuffer_Imp.h"

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
namespace ace {
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
	VertexBuffer_Imp::VertexBuffer_Imp(Graphics* graphics, int32_t size, int32_t count, bool isDynamic)
	: DeviceObject(graphics)
	, m_isDynamic(isDynamic)
	, m_size(size)
	, m_maxCount(count)
	, m_offset(0)
	, m_resource(NULL)
	, m_isLock(false)
	, m_ringBufferLock(false)
	, m_vertexOffset(0)
{

}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
VertexBuffer_Imp::~VertexBuffer_Imp()
{

}

//-----------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------
void* VertexBuffer_Imp::GetBufferDirect(int count)
{
	assert(m_isLock || m_ringBufferLock);
	if (m_offset / m_size + count > m_maxCount) return NULL;

	void* pBuffer = NULL;

	/* バッファに追記 */
	pBuffer = m_resource + m_offset;
	m_offset += count * m_size;

	return pBuffer;
}

//-----------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------
int VertexBuffer_Imp::GetMaxCount() const
{
	return m_maxCount;
}

//-----------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------
int VertexBuffer_Imp::GetSize() const
{
	return m_size;
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
}